<?php


App::import('Controller','Admin');
class CategoryController extends AdminController {
    public $uses = array('Category','CategoryLanguage');
    
    public function index() {
        App::import('model','Category');
        $out = "";
        Category::generateRow(1, $out,"");
        $this->set('categories',$out);
    }
    
    public function addcategory($categoryID=NULL){
        if($this->request->is('post')){
            if($categoryID != NULL){
                $this->request->data['Category']['category_id'] = $categoryID;
            }
            if($this->Category->save($this->request->data)){
                $this->Session->setFlash(__('Your Category has been saved.'), 'alert', array('plugin' => 'BoostCake','class' => 'alert-success'));
                return $this->redirect(array('action' => 'index'));
            }
        }
        if(!$this->request->data){
            $data = $this->Category->getCategoryID($categoryID);
            $this->request->data = $data;
        }
        $this->set('categories',$this->Category->createTree());
    }
    public function deletecategory($id){
        $this->Category->delete($id);
        $this->Session->setFlash(__('Delete category success.'), 'alert', array('plugin' => 'BoostCake','class' => 'alert-success'));
        
        return $this->redirect(array('action' => 'index'));
    }

}